package com.qss.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qs.mapper.SysLoginLogMapper;
import com.qs.pojo.SysLoginLog;
import com.qs.pojo.SysLoginLogExample;
import com.qss.service.LoginLogService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description
 * @user HP
 * @email 1460961774@qq.com
 * @Date 2021-10-08 15:53
 * @packageName com.qss.service.impl
 */@Service(interfaceClass = LoginLogService.class,timeout = 10000)
public class LoginLogServiceImpl implements LoginLogService {
     @Autowired
     private SysLoginLogMapper mapper;

    @Override
    public boolean saveLogin(SysLoginLog L) {
        return mapper.insertSelective(L)==1;
    }

    @Override
    public PageInfo<SysLoginLog> queryUsers(SysLoginLog user, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        SysLoginLogExample ex = new SysLoginLogExample();
        SysLoginLogExample.Criteria criteria = ex.createCriteria();
            if (user!=null){
                if (user.getUserId()!=null){
                    criteria.andLoginIdEqualTo(user.getUserId());
                }
            }
        List<SysLoginLog> users = mapper.selectByExample(ex);
        return new PageInfo(users);
    }

    @Override
    public SysLoginLog queryUserById(Integer loginId) {
        return mapper.selectByPrimaryKey(loginId);
    }

    @Override
    public boolean saveUser(SysLoginLog user) {
        if(user.getLoginId()!=null){
            int flag =mapper.updateByPrimaryKeySelective(user);
            return flag==1?true:false;
        }
        int flag = mapper.insertSelective(user);
        return flag==1?true:false;
    }

    @Override
    public boolean delUserById(Integer[] ids) {
        boolean status = false;
        int num=0;
        for(Integer id:ids){
            num+=mapper.deleteByPrimaryKey(id);
        }
        return num==ids.length?true:false;
    }
}
